<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Coupon_list;
use App\Coupon_pin;
use zgldh\QiniuStorage\QiniuStorage;

class ShopController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
        $data=Coupon_list::all();
        return json_encode(['code'=>'1001','msg'=>'拼团列表展示','data'=>$data]);
    }

    public function info($id){
        $data=Coupon_list::findOrFail($id);
        return json_encode(['code'=>'1001','msg'=>'拼团详情','data'=>$data]);

    }


    public function assemble($id){
//        $list=Coupon_list::findOrFail($id);
//        $data_list=json_decode($list,true);
//        var_dump($data_list);
        $pin=Coupon_pin::where('list_id','=',$id)->get();
//        $a=Coupon_pin::where('pin_num','=','2')->get();

            return json_encode(['code'=>'1001','msg'=>'拼团人员','data'=>$pin]);
        }

    //去参团
    public function goassemble(){
        //接ID
        $id=$_GET['id'];
        //查数据
        $data['data']=Coupon_pin::findOrFail($id);
        //查到list_id
        $list_id=$data['data']['list_id'];
        //查到list_id对应的coupon_list下面的这一条id的数据
        $pin['pin']=Coupon_list::where('id','=',$list_id)->first();
//        var_dump($pin);die;
        return json_encode(['code'=>'1001','msg'=>'拼团','data'=>$data,'pin'=>$pin]);
    }


    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
